SELECT 
    SUM(gdp) AS total_gdp, 
    SUM(population) AS total_pop, 
    COUNT(*) AS n_regions, 
    SUM(gdp)/SUM(population) AS welfare,
    regions.name
FROM countries
JOIN regions
ON countries.region=regions.id
GROUP BY regions.name
ORDER BY welfare DESC;

SELECT countries.name, regions.name FROM regions
JOIN countries
ON countries.region=regions.id
WHERE countries.gdp=(
    SELECT min(gdp) FROM countries
);

SELECT countries.name FROM countries
JOIN regions
ON countries.region=regions.id
WHERE countries.population>(
    SELECT avg(population) FROM countries
    JOIN regions
    ON countries.region=regions.id
    WHERE regions.name='Europe'
)
AND regions.name='Europe';